#include "widget.h"
#include "ui_widget.h"
#include "linechart.h"
#include<stdlib.h>
#include<QTime>
#include<QGridLayout>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    lineChart= new LineChart(ui->widget);
    QGridLayout * layout = new QGridLayout;
    layout->addWidget(lineChart,0,0,1,1);
    layout->addWidget(ui->pushButton,1,0,1,1);
    layout->setRowStretch(0, 30);
    layout->setRowStretch(1, 1);
//    layout->setMargin(0);
    setLayout(layout);

    ui->pushButton->raise();  // 你可以使用raise()和lower()函数来改变控件的Z序

    timer = new QTimer();
    connect(timer, &QTimer::timeout, this, &Widget::timeUpdate);
    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));

}


Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
  timer->start(300);
}


void Widget::timeUpdate()
{
    int rand = qrand()%50;    // 产生0-50范围内的随机数
    lineChart->addPoint(rand);
}




//void Widget::paintEvent(QPaintEvent *)
//{
//    int side =qMin(width(),height());
//    this->setGeometry((width()-side)/2,(height()-side)/2,side,side);
//}
